var express = require('express');
var router = express.Router();
//引入数据库包
var db = require("./db.js");


/**
 * 查询列表页
 */
router.get('/', function (req, res, next) {
    db.query('select * from info', function (err, rows) {
        console.log(rows);
        if (err) {
            res.render('info/info', {title: 'nodeJsDemo', datas: []});
        } else {
            res.render('info/info', {title: 'nodeJsDemo', datas: rows});
        }
    })
});
router.get('/view/:id', function (req, res) {
    var id = req.params.id;
    console.log(id);
    db.query("select * from info where id=" + id, function (err, rows) {
        if (err) {
            res.send("修改跳转失败"+err)
        } else {
            res.render("info/view", {datas: rows});       //直接跳转
        }
    });
});
module.exports = router;